package cc.abanlee.module.system.controller.admin.demo;

import cc.abanlee.framework.common.pojo.CommonResult;
import cc.abanlee.module.system.controller.admin.demo.vo.DemoReqVO;
import cc.abanlee.module.system.controller.admin.demo.vo.DemoRespVO;
import cc.abanlee.module.system.service.demo.DemoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/demo")
@Validated
public class DemoController {

    @Resource
    private DemoService demoService;

    @PreAuthorize("hasAuthority('ROLE_admin')")
    @PostMapping("/test")
    public CommonResult<DemoRespVO> test(@RequestBody @Valid DemoReqVO demoReqVO){
        return CommonResult.success(demoService.test(demoReqVO));
    }

    //@PreAuthorize("hasAnyRole('admin')")
    @GetMapping("/test2")
    public CommonResult<DemoRespVO> test2(@RequestParam("id") @NotNull(message = "编号不能为空") Long id){
        return CommonResult.success(demoService.test2(id));
    }


    @GetMapping("/test3")
    public CommonResult<DemoRespVO> test3(@RequestParam("id") @NotNull(message = "编号不能为空") Long id){
        return CommonResult.success(demoService.test2(id));
    }
}
